package com.datashare.dataentryods.controller;

import com.datashare.dataentryods.domain.IYjzfbl;
import com.datashare.dataentryods.service.IYjzfblService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 多级菜单示例信息Controller
 * 
 * @author lhj
 * @date 2022-02-11
 */
@RestController
@RequestMapping("/yjzf/zfbl")
public class IYjzfblController extends BaseController
{
    @Autowired
    private IYjzfblService iYjzfblService;

    /**
     * 查询多级菜单示例信息列表
     */
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:list')")
    @GetMapping("/list")
    public TableDataInfo list(IYjzfbl iYjzfbl)
    {
        startPage();
        List<IYjzfbl> list = iYjzfblService.selectYjzfblList(iYjzfbl);
        return getDataTable(list);
    }

    /**
     * 导出多级菜单示例信息列表
     */
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:export')")
    @Log(title = "多级菜单示例信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IYjzfbl iYjzfbl)
    {
        List<IYjzfbl> list = iYjzfblService.selectYjzfblList(iYjzfbl);
        ExcelUtil<IYjzfbl> util = new ExcelUtil<IYjzfbl>(IYjzfbl.class);
        util.exportExcel(response, list, "多级菜单示例信息数据");
    }

    /**
     * 获取多级菜单示例信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:query')")
    @GetMapping(value = "/{yjzfblId}")
    public AjaxResult getInfo(@PathVariable("yjzfblId") Long yjzfblId)
    {
        return AjaxResult.success(iYjzfblService.selectYjzfblByYjzfblId(yjzfblId));
    }

    /**
     * 新增多级菜单示例信息
     */
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:add')")
    @Log(title = "多级菜单示例信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody IYjzfbl iYjzfbl)
    {
        return toAjax(iYjzfblService.insertYjzfbl(iYjzfbl));
    }

    /**
     * 修改多级菜单示例信息
     */
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:edit')")
    @Log(title = "多级菜单示例信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody IYjzfbl iYjzfbl)
    {
        return toAjax(iYjzfblService.updateYjzfbl(iYjzfbl));
    }

    /**
     * 删除多级菜单示例信息
     */
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:remove')")
    @Log(title = "多级菜单示例信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{yjzfblIds}")
    public AjaxResult remove(@PathVariable Long[] yjzfblIds)
    {
        return toAjax(iYjzfblService.deleteYjzfblByYjzfblIds(yjzfblIds));
    }

    /**
    * 导入多级菜单示例信息
    */
    @Log(title = "多级菜单示例信息", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('yjzf:zfbl:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<IYjzfbl> util = new ExcelUtil<IYjzfbl>(IYjzfbl.class);
        List<IYjzfbl> dataList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = iYjzfblService.importYjzfbl(dataList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
    * 下载导入模板
    */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<IYjzfbl> util = new ExcelUtil<IYjzfbl>(IYjzfbl.class);
        util.importTemplateExcel(response, "多级菜单示例信息数据");
    }
}
